package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.LabProjectWorkResearch;
import com.ruoyi.system.service.ILabProjectWorkResearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 实验室工作研究课题Controller
 *
 * @author jun.wang
 * @date 2022-04-12
 */
@RestController
@RequestMapping("/system/workResearch")
public class LabProjectWorkResearchController extends BaseController {
    @Autowired
    private ILabProjectWorkResearchService labProjectWorkResearchService;

    /**
     * 查询实验室工作研究课题列表
     */
//    // @PreAuthorize("@ss.hasPermi('system:research:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabProjectWorkResearch labProjectWorkResearch) {
        startPage();
        List<LabProjectWorkResearch> list = labProjectWorkResearchService.selectLabProjectWorkResearchList(labProjectWorkResearch);
        return getDataTable(list);
    }

    /**
     * 导出实验室工作研究课题列表
     */
    // @PreAuthorize("@ss.hasPermi('system:research:export')")
    @Log(title = "实验室工作研究课题", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LabProjectWorkResearch labProjectWorkResearch) {
        List<LabProjectWorkResearch> list = labProjectWorkResearchService.selectLabProjectWorkResearchList(labProjectWorkResearch);
        ExcelUtil<LabProjectWorkResearch> util = new ExcelUtil<LabProjectWorkResearch>(LabProjectWorkResearch.class);
        return util.exportExcel(list, "research");
    }

    /**
     * 获取实验室工作研究课题详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:research:query')")
    @GetMapping(value = "/{instanceId}")
    public AjaxResult getInfo(@PathVariable("instanceId") Long instanceId) {
        return AjaxResult.success(labProjectWorkResearchService.selectLabProjectWorkResearchById(instanceId));
    }

    /**
     * 新增实验室工作研究课题
     */
    // @PreAuthorize("@ss.hasPermi('system:research:add')")
    @Log(title = "实验室工作研究课题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabProjectWorkResearch labProjectWorkResearch) {
        return toAjax(labProjectWorkResearchService.insertLabProjectWorkResearch(labProjectWorkResearch));
    }

    /**
     * 修改实验室工作研究课题
     */
    // @PreAuthorize("@ss.hasPermi('system:research:edit')")
    @Log(title = "实验室工作研究课题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabProjectWorkResearch labProjectWorkResearch) {
        return toAjax(labProjectWorkResearchService.updateLabProjectWorkResearch(labProjectWorkResearch));
    }

    /**
     * 删除实验室工作研究课题
     */
    // @PreAuthorize("@ss.hasPermi('system:research:remove')")
    @Log(title = "实验室工作研究课题", businessType = BusinessType.DELETE)
    @DeleteMapping("/{instanceIds}")
    public AjaxResult remove(@PathVariable Long[] instanceIds) {
        return toAjax(labProjectWorkResearchService.deleteLabProjectWorkResearchByIds(instanceIds));
    }
}
